import java.util.*;

abstract class aList{
	protected int id = -1;
	private String title;
	private cardInfor cardList = null;
	protected boolean enabled = true;  // list is archived or not
	protected String comment = null;
	
	abstract void createNewList(String aListName,int listId); //creat a new list
	abstract void attachCardList(cardInfor cardList);
	abstract void edit(String newTitle);
	abstract void archiving();
	abstract void unarchiving();
	abstract void remove();
	abstract void setComment(String comment);
	
	
	protected String getComment(){
		return this.comment;
	}
	
	// set a list's name/title
	protected void setTitle(String name){
		this.title = name;
	}
		
	// get a list's name/title
	protected String getTitle(){
		return this.title;
	}
	
	// get the number of card on the List
	protected int getNumOfCardOnTheList(){
		if (cardList == null) return 0;
		return cardList.getCardSize();
	}
	
	// do real action of attaching a cardList to the List 
	protected void setCardList(cardInfor cardList){
		this.cardList = cardList;
	}
	
	protected card getCardOnList(String cardTitle){
		card doc = null;
		//doc = cardList.getCard(cardTitle);
		return doc;
	}
	protected int getId(){
		return this.id;
	}
	protected ArrayList<card> getAllCard(){
		return this.cardList.getAll();
	}
	
}

abstract class aListEditor{
	private ArrayList<aList> aListList = new ArrayList<aList>(); // an arrayList to store lists

	
	private aList findList(int listId){
		for(aList doc : aListList) {
            if (listId == doc.getId()){
            	return doc;
            }
        }
		aList doc = null;
		return doc;
	}
	
	void createNewList(String file,int listId) {
        aList doc = createList();
        doc.createNewList(file,listId);
        aListList.add(doc);
    }
	
	/*
	 *  attach a cardList to specific List
	 *  parameter :
	 *  	cardList is a sequence that want to attach to a List  
	 *  	aListTitle is the target card's name to be attached
	 */ 
	void attachCardList(cardInfor cardList,String aListTitle){
		for(aList doc : aListList) {
			if (doc.getTitle() == aListTitle){
            	doc.attachCardList(cardList);
            }
        }
	}
	
	// print all the List name/title in the array 
	void getAllListTitle(){
    	for(aList doc : aListList) {
    		System.out.println("aListTitle =  " + doc.getTitle());
        }
    }
	
	int getNumOfCardOnTheList(String aListTitle){
		for(aList doc : aListList) {
			if (doc.getTitle() == aListTitle){
            	return doc.getNumOfCardOnTheList();
            }
        }
		return 0;
	}
	int getListSize(){
		return aListList.size();
	}
	
	void editComment(int targetId,String comment){
		aList doc = findList(targetId);
		doc.setComment(comment);
	}
	void editTitle(int targetId,String newTitle){
		aList doc = findList(targetId);
		doc.setTitle(newTitle);
	}
	void editRemove(int targetId){
		aList doc = findList(targetId);
		doc.remove();
	}
	void editArchiving(int targetId){
		aList doc = findList(targetId);
		doc.archiving();
	}
	void editUnarchiving(int targetId){
		aList doc = findList(targetId);
		doc.unarchiving();
	}
	aList getList(int listId){
		return findList(listId);
	}
	protected card getCardOnList(int targetId,String cardTitle){
		aList doc = findList(targetId);
		return doc.getCardOnList(cardTitle);
	}
	public ArrayList<aList> getAll(){
		return this.aListList;
	}
	abstract aList createList();
}

//to define all the methods
class aListInfor extends aListEditor{
	aList createList() {
		return new aList() {
			void createNewList(String aListName,int listId){
				this.setTitle(aListName);
				this.id = listId;
				this.unarchiving();
				//System.out.println("createNewList " + this.getTitle());
			}
			
			void attachCardList(cardInfor cardList){

				this.setCardList(cardList);
				
			}
			void edit(String newTitle){
				this.setTitle(newTitle);
			}
			void archiving(){
				this.enabled = false;
			}
			void unarchiving(){
				this.enabled = true;
			}
			void remove(){
				
				/*
    			 * here have to DELETE : 
    			 * 		1. the list associated with its id
    			 * 		2. all cards on the list
    			 * form DATABASE
    			 */
				
			}
			void setComment(String comment){
				this.comment = comment;
			}
		};
	}
}

/*
 *   We have to write an interface to connect Board, List,Card....
 *   
 */
